<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/18
 * Time: 10:06
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Other extends Base
{
    /**
     * 保修政策
     * @return mixed|\think\response\Json
     */
    public function baoXiu(){
        if(Request::instance()->isPost()){
            $content = input('content');

            $update = [
                'id' => 1,
                'content' => $content,
                'update_time' => createTime()
            ];
            $res = Db::table('up_other')->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_other')->where('id', 1)->field('content')->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 用户协议
     * @return mixed|\think\response\Json
     */
    public function userAgreement(){
        if(Request::instance()->isPost()){
            $content = input('content');

            $update = [
                'id' => 2,
                'content' => $content,
                'update_time' => createTime()
            ];
            $res = Db::table('up_other')->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_other')->where('id', 2)->field('content')->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 隐私协议
     * @return mixed|\think\response\Json
     */
    public function ysAgreement(){
        if(Request::instance()->isPost()){
            $content = input('content');

            $update = [
                'id' => 3,
                'content' => $content,
                'update_time' => createTime()
            ];
            $res = Db::table('up_other')->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_other')->where('id', 3)->field('content')->find();
        $this->assign('data', $data);
        return $this->fetch();
    }
}